/*----------------------------------------------------------------------
  - File name      : STC8Ax_NVIC.c
  - Author         : Quark Team
  - Update date    : 2020-08-28                   
  -	Copyright      : Gevico Electronic studio   
  - Module comments: NVIC module.
-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/
#include "STC8Ax_NVIC.h"
/*-----------------------------------------------------------------------
|                                 DATA                                  |
-----------------------------------------------------------------------*/
/* None */
/*-----------------------------------------------------------------------
|                               FUNCTION                                |
-----------------------------------------------------------------------*/

/*--------------------------------------------------------
| @Description: EXTI0 trigger mode function              |
| @param      : EXTITri_Type TriState                    |     
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE EXTI0_TRIMode_Init(EXTITri_Type TriState)
{
	IT0 = TriState;
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: EXTI1 trigger mode function              |
| @param      : EXTITri_Type TriState                    |     
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE EXTI1_TRIMode_Init(EXTITri_Type TriState)
{
	IT1 = TriState;
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: EXTI0 NVIC function                      |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_EXTI0_Init(NVICPri_Type Priority,FUNSTATE State)
{
	EX0 = State;
    EXTI0_NVIC_PRI(Priority);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: EXTI1 NVIC function                      |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_EXTI1_Init(NVICPri_Type Priority,FUNSTATE State)
{
	EX1 = State;
    EXTI1_NVIC_PRI(Priority);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: EXTI2 NVIC function                      |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_EXTI2_Init(NVICPri_Type Priority,FUNSTATE State)
{
	if(Priority == NVIC_FIX)
	{
		INTCLKO = (INTCLKO & 0xEF) | (State << 4);
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: EXTI3 NVIC function                      |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_EXTI3_Init(NVICPri_Type Priority,FUNSTATE State)
{
	if(Priority == NVIC_FIX)
	{
		INTCLKO = (INTCLKO & 0xDF) | (State << 5);
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: EXTI3 NVIC function                      |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_EXTI4_Init(NVICPri_Type Priority,FUNSTATE State)
{
	if(Priority == NVIC_FIX)
	{
		INTCLKO = (INTCLKO & 0xBF) | (State << 6);
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: TIMER0 NVIC function                     |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_TIMER0_Init(NVICPri_Type Priority,FUNSTATE State)
{
	ET0 = State;
    TIMER0_NVIC_PRI(Priority);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: TIMER1 NVIC function                     |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_TIMER1_Init(NVICPri_Type Priority,FUNSTATE State)
{
	ET1 = State;
    TIMER1_NVIC_PRI(Priority);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: TIMER2 NVIC function                     |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_TIMER2_Init(NVICPri_Type Priority,FUNSTATE State)
{
	if(Priority == NVIC_FIX)
	{
	    IE2 = (IE2 & 0xFB) | (State << 2);
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: TIMER3 NVIC function                     |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_TIMER3_Init(NVICPri_Type Priority,FUNSTATE State)
{
	if(Priority == NVIC_FIX)
	{
		IE2 = (IE2 & 0xDF) | (State << 5);
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: TIMER4 NVIC function                     |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_TIMER4_Init(NVICPri_Type Priority,FUNSTATE State)
{
	if(Priority == NVIC_FIX)
	{
		IE2 = (IE2 & 0xBF) | (State << 6);
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: UART1 NVIC function                      |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_UART1_Init(NVICPri_Type Priority,FUNSTATE State)
{
	ES = State;
	UART1_NVIC_PRI(Priority); 
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: UART2 NVIC function                      |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_UART2_Init(NVICPri_Type Priority,FUNSTATE State)
{
	IE2 = (IE2 & 0xFE) | (State);
    UART2_NVIC_PRI(Priority);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: UART3 NVIC function                      |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_UART3_Init(NVICPri_Type Priority,FUNSTATE State)
{
	if(Priority == NVIC_FIX)
	{
		IE2 = (IE2 & 0xF7) | (State << 3);
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: UART4 NVIC function                      |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_UART4_Init(NVICPri_Type Priority,FUNSTATE State)
{
	if(Priority == NVIC_FIX)
	{
		IE2 = (IE2 & 0xEF) | (State << 4);
		return FSC_SUCCESS;
	}
	else return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: COMP NVIC function                       |
| @param      : NVICPri_Type Priority,                   |
|               uint8 State                              |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_COMP_Init(NVICPri_Type Priority,COMPTri_Type TriState)
{
	COMP_TRIState_Init(TriState);
	COMP_NVIC_PRI(Priority);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: ADC NVIC function                        |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_ADC_Init(NVICPri_Type Priority,FUNSTATE State)
{
	EADC = State;
	ADC_NVIC_PRI(Priority);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: LVD NVIC function                        |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_LVD_Init(NVICPri_Type Priority,FUNSTATE State)
{
	ELVD = State;
	LVD_NVIC_PRI(Priority);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PCA Counter NVIC function                |
| @param      : NVICPri_Type Priority,                   |
|               FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PCA_CNT_Init(NVICPri_Type Priority,FUNSTATE State)
{
	CMOD |= State;
	PCA_NVIC_PRI(Priority);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PCA0 Timer and POP NVIC function         |
| @param      : FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PCA0_TIM_POP_Init(FUNSTATE State)
{
	CCAPM0 = (CCAPM0 & 0xFE) | (State);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PCA1 Timer and POP NVIC function         |
| @param      : FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PCA1_TIM_POP_Init(FUNSTATE State)
{
	CCAPM1 = (CCAPM1 & 0xFE) | (State);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PCA2 Timer and POP NVIC function         |
| @param      : FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PCA2_TIM_POP_Init(FUNSTATE State)
{
	CCAPM2 = (CCAPM2 & 0xFE) | (State);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PCA3 Timer and POP NVIC function         |
| @param      : FUNSTATE State                           |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PCA3_TIM_POP_Init(FUNSTATE State)
{
	CCAPM3 = (CCAPM3 & 0xFE) | (State);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PCA0 PWM and CAP NVIC function           |
| @param      : uint8 State                              |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PCA0_PWM_CAP_Init(PCATri_Type TriState)
{
	CCAPM0 = (CCAPM0 & 0xCE) | (TriState);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PCA1 PWM and CAP NVIC function           |
| @param      : uint8 State                              |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PCA1_PWM_CAP_Init(PCATri_Type TriState)
{
	CCAPM1 = (CCAPM1 & 0xCE) | (TriState);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PCA2 PWM and CAP NVIC function           |
| @param      : uint8 State                              |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PCA2_PWM_CAP_Init(PCATri_Type TriState)
{
	CCAPM2 = (CCAPM2 & 0xCE) | (TriState);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PCA3 PWM and CAP NVIC function           |
| @param      : uint8 State                              |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PCA3_PWM_CAP_Init(PCATri_Type TriState)
{
	CCAPM3 = (CCAPM3 & 0xCE) | (TriState);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PWM CNT return to zero NVIC function     |
| @param      : uint8 State                              |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PWM_CNT_Init(NVICPri_Type Priority,FUNSTATE State)
{
	PWM_CNT_NVIC_PRI(Priority);
	PWMCR = (PWMCR & 0xBF) | (State << 6);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PWM abnormal detection NVIC function     |
| @param      : uint8 State                              |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PWM_ABD_Init(NVICPri_Type Priority,FUNSTATE State)
{
	EAXFR_ENABLE();
	PWM_ABD_NVIC_PRI(Priority);
	PWMFDCR = (PWMFDCR & 0xF7) | (State << 3);
	EAXFR_DISABLE();
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PWM0 road flip NVIC function             |
| @param      : PWMFlip_Type Flstate                     |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PWM0_Init(PWMFlip_Type Flstate)
{
	EAXFR_ENABLE();
	PWMxCR(PWM0CR_ADDRESS) = (PWMxCR(PWM0CR_ADDRESS) & 0xF8) | (Flstate);
	EAXFR_DISABLE();
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PWM1 road flip NVIC function             |
| @param      : PWMFlip_Type Flstate                     |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PWM1_Init(PWMFlip_Type Flstate)
{
	EAXFR_ENABLE();
	PWMxCR(PWM1CR_ADDRESS) = (PWMxCR(PWM1CR_ADDRESS) & 0xF8) | (Flstate);
	EAXFR_DISABLE();
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PWM2 road flip NVIC function             |
| @param      : PWMFlip_Type Flstate                     |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PWM2_Init(PWMFlip_Type Flstate)
{
	EAXFR_ENABLE();
	PWMxCR(PWM2CR_ADDRESS) = (PWMxCR(PWM2CR_ADDRESS) & 0xF8) | (Flstate);
	EAXFR_DISABLE();
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PWM3 road flip NVIC function             |
| @param      : PWMFlip_Type Flstate                     |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PWM3_Init(PWMFlip_Type Flstate)
{
	EAXFR_ENABLE();
	PWMxCR(PWM3CR_ADDRESS) = (PWMxCR(PWM3CR_ADDRESS) & 0xF8) | (Flstate);
	EAXFR_DISABLE();
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PWM4 road flip NVIC function             |
| @param      : PWMFlip_Type Flstate                     |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PWM4_Init(PWMFlip_Type Flstate)
{
	EAXFR_ENABLE();
	PWMxCR(PWM4CR_ADDRESS) = (PWMxCR(PWM4CR_ADDRESS) & 0xF8) | (Flstate);
	EAXFR_DISABLE();
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PWM5 road flip NVIC function             |
| @param      : PWMFlip_Type Flstate                     |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PWM5_Init(PWMFlip_Type Flstate)
{
	EAXFR_ENABLE();
	PWMxCR(PWM5CR_ADDRESS) = (PWMxCR(PWM5CR_ADDRESS) & 0xF8) | (Flstate);
	EAXFR_DISABLE();
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PWM6 road flip NVIC function             |
| @param      : PWMFlip_Type Flstate                     |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PWM6_Init(PWMFlip_Type Flstate)
{
	EAXFR_ENABLE();
	PWMxCR(PWM6CR_ADDRESS) = (PWMxCR(PWM6CR_ADDRESS) & 0xF8) | (Flstate);
	EAXFR_DISABLE();
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: PWM7 road flip NVIC function             |
| @param      : PWMFlip_Type Flstate                     |         
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_PWM7_Init(PWMFlip_Type Flstate)
{
	EAXFR_ENABLE();
	PWMxCR(PWM7CR_ADDRESS) = (PWMxCR(PWM7CR_ADDRESS) & 0xF8) | (Flstate);
	EAXFR_DISABLE();
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: SPI init NVIC function                   |
| @param      : NVICPri_Type Priority,FUNSTATE State     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVIC_SPI_Init(NVICPri_Type Priority,FUNSTATE State)
{
	SPI_NVIC_PRI(Priority);
	IE2 = (IE2 & 0xFD) | (State << 1);
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: I2C Master init NVIC function            |
| @param      : NVICPri_Type Priority,FUNSTATE State     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVCI_I2C_Master_Init(NVICPri_Type Priority,FUNSTATE State)
{
	EAXFR_ENABLE();
	I2C_NVIC_PRI(Priority);
	I2CMSCR = State << 7;
	EAXFR_DISABLE();
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: I2C Slave init NVIC function             |
| @param      : NVICPri_Type Priority,                   |
|               I2CSTri_Type TriState                    |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE NVCI_I2C_Slave_Init(NVICPri_Type Priority,I2CSTri_Type TriState)
{
	EAXFR_ENABLE();
	I2C_NVIC_PRI(Priority);
	I2CMSCR &= 0x7F;
	I2CSLCR &= (I2CSLCR & 0x01 )| (TriState);
	EAXFR_DISABLE();
	return FSC_SUCCESS;
}

/*-----------------------------------------------------------------------
|          END OF FLIE        (C) COPYRIGHT Gevico Electronics          | 
-----------------------------------------------------------------------*/



